home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / HDX_BACK / HDX302.ST / DESKDIR.BAK < prev    next >
Encoding:
Text File  |  2001-02-09  |  21.3 KB  |  1,042 lines

  1. /*    DESKDIR.C        7/31/89            Jian Ye        */
  2. /*    Fix the count operation    8/1/89            D.Mui        */
  3. /*     Change and fix another bug in the count()    8/2/89    J.Ye    */
  4. /*     8/7/89                            J.Ye    */
  5. /*     Add the check point in the countrec(). When the Depth of path    */
  6. /*     reach the 9 level, the system stack will over flow         */
  7. /*    Fix at rmfile    8/8/89            D.Mui            */
  8. /*    Fix count     8/8/89                        */
  9. /*    Fix the delete() for root dir        8/9/89            */
  10. /*    Fix at chkfile, close file after opening it    8/15/89    D.Mui    */
  11. /*     Fix tow bugs in the chkfile() and chkdir() so that they check    */
  12. /*        the second name conflict.        8/17/89    J.Ye    */
  13. /*     Optimize, simplify, compact this function.    8/27/89 J.Ye    */
  14. /*    Modify edname                    9/6/89    D.Mui    */
  15. /*    Take out wdesk,hdesk    9/7/89            D.Mui        */
  16. /*     simplify the single flopy disk copy        9/11/89    J.Ye    */
  17.  
  18. #include <portab.h>    
  19. #include <osbind.h>
  20. #include <mobdefs.h>
  21. #include <gemdefs.h>
  22. #include <window.h>
  23. #include <defines.h>
  24. #include <deskusa.h>
  25. #include <error.h>
  26. #include <extern.h>
  27.  
  28. EXTERN    char     *strcat();
  29. EXTERN    char     *strcpy();
  30. EXTERN     int     d_next();
  31. EXTERN    OBJECT    *get_tree();
  32.  
  33. /* "DMA" buffer structure for Fsfirst() and Fsnext().    */
  34.  
  35. typedef struct {
  36.     char    d_glob[12];    /* GEMDOS wildcard string from Fsfirst */
  37.     char    d_mask;        /* Attribute mask from Fsfirst */
  38.     char    d_dirent[4];    /* Offset into directory, MSB first */
  39.     char    d_dirid[4];    /* Pointer to directory structure in GEM mem */
  40.     char    d_fattr;    /* File attributes */
  41.     long    d_tandd;    /* Time and date words */
  42.     long    d_fsize;    /* File size */
  43.     char     d_fname[14];    /* File name */
  44. } DMABUFFER;
  45.  
  46. #define OK    1
  47. #define CHECK    -9
  48. #define DTOD    3
  49. #define FILE_LEN 12
  50. #define HOME    '.'
  51. #define MAXDEPTH 8
  52.  
  53. OBJECT     *cpbox;            /* cp or rm or mv dialog box */
  54.  
  55. int    srclen, dstlen;        /* the size of source and target buffer */
  56. long    numfiles,numdirs;    /* the number of files and dirs show in the dialog box*/
  57. long    tolsize;        /* the total size of all files in the path */
  58. int    srcbuf, dstbuf;    /* the size of source and target buffer be define */
  59. int    f_level;    /* the current depth of the directory path */
  60. int    f_abort;    /* the flag for the abort button selected */
  61. int    opcode;        /* the operation codes for cp, mv and rm */
  62. int    d_display;    /* display copy box or not        */
  63. int    back_update;    /* update background    */
  64. int    namecon, rename;
  65.  
  66.             /* the source and target string pointer */    
  67. char     *fixsrc, *fixdst;    
  68.  
  69. char *getall = "*.*";
  70. char *bckslsh = "\\";
  71. char *curall = ".\\*.*";
  72. char *baklvl = ".\\..";
  73.  
  74.  
  75. char *filestr = "abcdefgh.abcd";    /* the buffer for the file */
  76.  
  77.  
  78. /*    Main entrance of the file operation function    */
  79.  
  80. dofiles(s, d, code, ndirs, nfiles, tsize)
  81.     char *s, *d;
  82.     int code;
  83.     long *ndirs, *nfiles, *tsize;
  84. {
  85.     int ret,trash;
  86.  
  87.     desk_wait( TRUE );
  88.                 /* get the dialog box string */
  89.     cpbox = get_tree( CPBOX );
  90.  
  91.     f_level = 1;        /* the current depth of the directory path */
  92.     f_abort = 0;
  93.     rename    = 0;
  94.  
  95.     back_update = FALSE;
  96.  
  97.     if ( (opcode = code) == OP_COUNT )
  98.     {
  99.       numfiles = 0x0L;    /* the number of files show in the dialog box */
  100.       numdirs = 0x0L;    /* the number of directories */
  101.       tolsize = 0x0L;    /* the total size of all files in the path */
  102.     }
  103.     else
  104.     {
  105.       numdirs = *ndirs;
  106.       numfiles = *nfiles;
  107.       tolsize = *tsize;
  108.     }
  109.  
  110.     do
  111.     {
  112.          if (code == OP_COUNT)
  113.       {
  114.         if ( !(ret = count( s ) ) )
  115.           goto clnup;        /* error    */
  116.       }
  117.       else
  118.       {    
  119.         if (!(ret = getinfo(s, d)))
  120.           goto clnup;
  121.         else if (ret == SKIP)
  122.           continue;
  123.  
  124.         if (!(ret = doright(ret)))
  125.           goto clnup;
  126.       }
  127.  
  128.     }while ( d_next( &s, &trash ) );
  129.     
  130.     *ndirs = numdirs;
  131.     *nfiles = numfiles;
  132.     *tsize = tolsize;
  133.  
  134. clnup:
  135.     desk_wait( FALSE );
  136.  
  137.     if ( f_abort )
  138.       return( TRUE );
  139.  
  140.     return( ret );
  141. }
  142.  
  143. /* do the rm, cp and mv file job */
  144.  
  145. doright(flag)
  146. int flag;
  147. {
  148.     int     ret,retmsg=TRUE;
  149.     char    *temp, buf[14];
  150.  
  151.     if (opcode == OP_DELETE)
  152.     {
  153.         temp = fixdst;
  154.         fixdst = fixsrc;
  155.     }
  156.     if (flag == DTOD)
  157.     {
  158.         if (!(retmsg=doact()))
  159.             goto endright;
  160.         if (opcode != OP_COPY)
  161.             retmsg = deleted();    /* rm the first folder */
  162.     }
  163.     else                    /* file to file */
  164.     {
  165.         getlastpath(filestr, fixdst);
  166.         backdir(fixdst);
  167.         getlastpath(buf, fixdst);
  168.         strcat(filestr, fixdst);
  169.         updatname(CPFILE, filestr);
  170.         updatname(CPDIR, buf);
  171.         if (opcode != OP_DELETE)
  172.             if ((!(retmsg = wrfile(filestr)))||(rename)||(retmsg == SKIP))
  173.                 goto endright;
  174.         if (opcode != OP_COPY)
  175.         {
  176. redel:
  177.                if ( (ret = Fdelete(fixsrc)) )    
  178.                {
  179.                 if ( (ret == 0xFFFA) || (ret == 0xFFFE) )    /* seek error or */
  180.                   {
  181.                     retmsg = FALSE;              /* drive not ready */
  182.                     goto endright;
  183.                   }
  184.  
  185.                   if ( do_alert( 1, CNTDELF ) == 2 )/* retry */    
  186.                     goto redel;
  187.                 else
  188.                 {
  189.                     f_abort = 1;
  190.                     retmsg = FALSE;
  191.                     goto endright;
  192.                 }
  193.             }
  194.             else
  195.             {        
  196.                 if (opcode == OP_DELETE)
  197.                       updatnum(NUMFILE, --numfiles);    
  198.                   updesk( fixsrc );
  199.             }
  200.         } 
  201.     }
  202.  
  203. endright:
  204.     Mfree(fixsrc);
  205.     if (opcode == OP_DELETE)
  206.         Mfree(temp);
  207.     else
  208.         Mfree(fixdst);
  209.     return(retmsg);
  210. }
  211.  
  212.  
  213. /* recursively cp or mv or rm files or directoies from a given path */
  214.  
  215. doact()
  216. {
  217.     char *saved;
  218.     DMABUFFER dumb;
  219.     int ret, retmsg;
  220.  
  221.     retmsg = TRUE;
  222.     saved = (DMABUFFER *)Fgetdta();
  223.     Fsetdta(&dumb);
  224.     strcat(getall, fixsrc);
  225.  
  226.     if (!Fsfirst(fixsrc, 0xFF))    
  227.     {
  228.       do
  229.       {
  230.         if (dumb.d_fname[0] != HOME)    
  231.         {
  232.           if (SUBDIR & dumb.d_fattr)    
  233.           {
  234.         chkbuf(srclen, srcbuf, &fixsrc);        /* check buf size */
  235.         addfile(fixsrc, dumb.d_fname); /* add a dir into the path */
  236.         strcat(bckslsh, fixsrc);
  237.         if (opcode != OP_DELETE)
  238.         {
  239.             chkbuf(dstlen, dstbuf, &fixdst);        /* check buf size */
  240.             strcat(dumb.d_fname, fixdst);
  241.         }
  242.         else
  243.             goto dorec;
  244.  
  245.         updatbox(dumb.d_fname);
  246.     rechkd1:                         /* update check the dir existing or not */
  247.         switch( chkdf( dumb.d_fname, CPDIR ) ) 
  248.         {
  249.           case    QUIT:
  250.               f_abort = 1;
  251.               retmsg = FALSE;
  252.               goto mvend;
  253.           case    SKIP:
  254.               backdir(fixsrc);
  255.               backdir(fixdst);
  256.               updatnum(NUMDIR, --numdirs);
  257.               srclen -= FILE_LEN;        /* subtract the add lenth */
  258.               dstlen -= FILE_LEN;        /* subtract the add lenth */
  259.               retmsg = TRUE;
  260.               continue;
  261.           case     FALSE:
  262.               goto     mvend;
  263.           case     CHECK:
  264.              goto     rechkd1;
  265.           case     OK:
  266. recrtd:
  267.               if (Dcreate(fixdst))    
  268.               {
  269.                 if ( write_save )
  270.                        goto kk_1;
  271.  
  272.               switch( do_alert(1,CNTCRTDR))
  273.                 {    
  274.                   case 1:                    /* skip */
  275.                     backdir(fixsrc);
  276.                     backdir(fixdst);
  277.                     updatnum(NUMDIR, --numdirs);
  278.                     srclen -= FILE_LEN;    /* subtract the add lenth */
  279.                     dstlen -= FILE_LEN;    /* subtract the add lenth */
  280.                     continue;
  281.                 case 2:                    /* retry */
  282.                     goto recrtd;
  283.                   default:                 /* quit */
  284.                    f_abort = 1;
  285.                    retmsg = FALSE;
  286.                    goto mvend;
  287.                 }
  288.               }/* if recrtd */
  289.             break;
  290.         }
  291. kk_1:
  292.         updatnum(NUMDIR, --numdirs);
  293.         strcat(bckslsh, fixdst);
  294. dorec:
  295.         if (!doact())     /* do the recursion */
  296.         {
  297.           retmsg = FALSE;
  298.           goto mvend;
  299.         }
  300.         if (opcode == OP_COPY)
  301.             goto clndir;
  302.         rmstarb(fixsrc);        /* after call, -> c:\d1\ */
  303.         if (opcode == OP_DELETE)
  304.         {
  305.             getlastpath(filestr, fixsrc);
  306.             updatbox(filestr);
  307.         }
  308. remvd:
  309.         if (Ddelete(fixsrc))    
  310.         {                 /* delete a dir */
  311.           if ((ret = do_alert(1,CNTDELD)) == 2)    
  312.             goto remvd; /* retry */
  313.           else if (ret == 3)
  314.           {                 /* abort */
  315.             f_abort = 1;
  316.             retmsg = FALSE;
  317.             goto mvend;
  318.           }
  319.          }
  320.  
  321. clndir:
  322.         backdir(fixsrc);        /* back one dir */
  323.         srclen -= FILE_LEN;        /* subtract the add lenth */
  324.         if (opcode == OP_DELETE)
  325.             updatnum(NUMDIR, --numdirs);
  326.         else
  327.         {
  328.             backdir(fixdst);        /* back one dir */
  329.             dstlen -= FILE_LEN;        /* subtract the add lenth */
  330.         }
  331.         } 
  332.         else 
  333.         {
  334.         getlastpath(filestr, fixdst);
  335.         updatname(CPDIR, filestr);            /* update the dir */
  336.         updatname( CPFILE, dumb.d_fname );     /* update the file */
  337.         chkbuf(srclen, srcbuf, &fixsrc);        /* check buf size */
  338.         addfile(fixsrc, dumb.d_fname);
  339.         if (opcode != OP_DELETE)
  340.         {
  341.             chkbuf(dstlen, dstbuf, &fixdst);        /* check buf size */
  342.             addfile(fixdst, dumb.d_fname);
  343.             rename = 0;
  344.             if (!(retmsg = wrfile(dumb.d_fname)))
  345.               goto mvend;
  346.             if ((rename) || (retmsg == SKIP))
  347.               goto clnfile;
  348.         }
  349.         if (opcode == OP_COPY)
  350.             goto clnfile;
  351. remvf:
  352.         if (ret = (Fdelete(fixsrc)))     /* rm the file from source */
  353.         {
  354.           if ((ret == 0xFFFA) || (ret == 0xFFFE))
  355.           {
  356.               /* seek error or drive not ready */
  357.             retmsg = FALSE;
  358.             goto mvend;
  359.           }
  360.           if ((ret = do_alert(1,CNTDELF)) == 2)     /* retry */
  361.             goto remvf;
  362.           else if (ret == 3)    
  363.               {            /* abort */
  364.                 f_abort = 1;
  365.                 retmsg = FALSE;
  366.                 goto mvend;
  367.               }
  368.         }
  369.         else
  370.           updesk( fixsrc );
  371. clnfile:
  372.         backdir(fixsrc);        /* back one dir */
  373.         srclen -= FILE_LEN;        /* subtract the add lenth */
  374.         if (opcode == OP_DELETE)
  375.             updatnum(NUMFILE, --numfiles);
  376.         else
  377.         {
  378.             backdir(fixdst);        /* back one dir */
  379.             dstlen -= FILE_LEN;        /* subtract the add lenth */
  380.         }
  381.         }
  382.         } 
  383.       } while (!Fsnext());
  384.     }
  385.     else 
  386.       retmsg = FALSE;
  387.     
  388. mvend:
  389.     Fsetdta(saved);
  390.     return(retmsg);
  391. }
  392.  
  393.  
  394. /* set the right drive and call the recursive routine to do the counting */
  395.  
  396. count( s )
  397.     char *s;
  398. {
  399.     char *tmp;
  400.  
  401.     tmp = s;
  402.     while ( *tmp++ );
  403.  
  404.     if (*(tmp-2) == '*')        /* a dir */
  405.     {
  406.       set_dir( s );                /* set the path        */
  407.       return(countrec());        /* recursive count    */    
  408.     }
  409.     numfiles++;
  410.     return(TRUE);
  411. }
  412.  
  413.  
  414. /* counte the file and directory recursivly */
  415.  
  416. countrec()
  417. {
  418.     char     *saved;
  419.     DMABUFFER dumb;
  420.     int     retmsg;
  421.  
  422.     retmsg = TRUE;
  423.     saved = (DMABUFFER *)Fgetdta();
  424.     Fsetdta(&dumb);
  425.  
  426.     if (!Fsfirst(curall, 0xFF))    
  427.     {
  428.       do     
  429.       {
  430.         if (dumb.d_fname[0] != HOME)    
  431.         {
  432.           if (SUBDIR & dumb.d_fattr)    
  433.           {                           /* setpath to one more down */
  434.         if (Dsetpath(dumb.d_fname))    
  435.         {
  436.           retmsg = FALSE;
  437.           goto endrec;
  438.         }
  439.  
  440.             numdirs++;
  441.  
  442.         if ( ++f_level > MAXDEPTH )     
  443.         {
  444.           form_alert(1, "[1][Not enough system stack|for this operation.][  OK  ]");
  445.           retmsg = FALSE;
  446.           goto endrec;
  447.         }
  448.  
  449.         if (!countrec())    /* to the recursion setpath to one back */
  450.         {
  451.           retmsg = FALSE;
  452.           goto endrec;
  453.         }
  454.         f_level--;
  455.         if (Dsetpath(baklvl))    
  456.         {
  457.           retmsg = FALSE;
  458.           goto endrec;
  459.         }
  460.           }
  461.           else 
  462.           {
  463.         numfiles++;    /* add up the file count and size    */
  464.         tolsize += dumb.d_fsize;
  465.           }
  466.         } 
  467.           } while (!Fsnext());
  468.     }
  469.  
  470. endrec:
  471.     Fsetdta( saved );    /* reset the dta    */
  472.     return(retmsg);
  473. }
  474.  
  475.  
  476. /* Copy the file from the s to d */
  477.  
  478. wrfile( fstr )
  479.     char *fstr;
  480. {
  481.     int     ret, retmsg;
  482.     int     inhand,outhand;
  483.     int        time[2];
  484.     DMABUFFER *mydta;
  485.     char     *buffer, *saved;
  486.     long     copysiz, bufsiz, wrsiz, tmpsiz; 
  487.     int     crted=0, sttime=1;
  488.  
  489.     retmsg = TRUE;
  490.     rename = 0;
  491. open:
  492.  
  493.     if ((inhand = Fopen(fixsrc, 0)) < 0)    
  494.     {
  495.       if ((inhand == 0xFFFA) || (inhand == 0xFFFE))/* seek error or */    
  496.         return(FALSE);
  497.  
  498.       if ((ret = do_alert(1,CNTOPEN)) == 1)    /* skip */    
  499.       {
  500.         updatnum(NUMFILE, --numfiles);
  501.         return SKIP;
  502.       }
  503.       else if (ret == 2)            /* retry */
  504.           goto open;
  505.         else                 /* abort */
  506.           return(FALSE);
  507.     }
  508.  
  509.     saved = (DMABUFFER *)Fgetdta();
  510.     Fsetdta(mydta=(DMABUFFER *)Malloc((long)sizeof(DMABUFFER)));
  511.  
  512.     if (Fsfirst(fixsrc, 0xF7))    
  513.     {
  514.        retmsg = SKIP;
  515.        if (do_alert(1,RDERROR) == 2)    /* abort */
  516.        {
  517.             f_abort = 1;
  518.             retmsg = FALSE;
  519.        }
  520.        goto y2;
  521.     }
  522.     bufsiz = (long )Malloc(-1L);
  523.     buffer = (char *)Malloc(bufsiz);
  524.     copysiz = mydta->d_fsize;
  525.     Fdatime( &time, inhand, 0 );    /* read the time and date */
  526.     while (copysiz > 0)    
  527.     {
  528.       tmpsiz = (copysiz > bufsiz) ? bufsiz : copysiz;
  529.       if (Fread(inhand, tmpsiz, buffer) < 0)    
  530.       {
  531.           retmsg = SKIP;
  532.         if (crted)    Fdelete(fixdst);
  533.         if (do_alert(1,RDERROR) == 2)    
  534.         {                    /* abort */
  535.           f_abort = 1;
  536.           retmsg = FALSE;
  537.         }
  538.         goto y1;            /* skip */
  539.       }
  540.       if (sttime)
  541.       {
  542.           sttime = 0;
  543.         rechkd:
  544.             switch(chkdf(fstr, CPFILE))
  545.             {
  546.               case CHECK:    goto rechkd;
  547.               case    SKIP:    retmsg = SKIP;    
  548.                               goto y1;
  549.               case     QUIT:    f_abort = 1;
  550.                             retmsg = FALSE;
  551.                             goto y1;
  552.               case    FALSE:    retmsg = FALSE;
  553.                               goto y1;
  554.             }
  555.             if ((opcode == OP_MOVE)&&(*fixsrc == *fixdst))
  556.             {
  557.               if (Frename(0, fixsrc, fixdst))
  558.                   retmsg = FALSE;
  559.               rename = 1;
  560.               goto y1;
  561.             }
  562.  
  563.         create:
  564.         if ((outhand = Fcreate(fixdst, mydta->d_fattr&7)) < 0)    
  565.         {
  566.           if ((ret = do_alert(1,CNTCRTFL)) == 2)        /* retry */
  567.             goto create;
  568.           else if (ret == 3)                /* abort */
  569.             {
  570.                 f_abort = 1;
  571.                 retmsg = FALSE;
  572.             }
  573.           else    
  574.               retmsg = SKIP;
  575.           goto y1;
  576.         }
  577.         crted = 1;
  578.       }
  579.  
  580.       if ((wrsiz = Fwrite(outhand, tmpsiz, buffer)) < 0)    
  581.       {
  582.           retmsg = SKIP;
  583.            Fdelete(fixdst);
  584.         if (do_alert(1,WRERROR) == 2)    
  585.         {                    /* abort */
  586.             f_abort = 1;
  587.             retmsg = FALSE;
  588.         }
  589.         goto y0;
  590.        }
  591.         /* check if there are sufficent memory */
  592.         if (wrsiz != tmpsiz)        { /* not sufficent memory ??*/
  593.             do_alert( 1,STDISKFU );
  594.             f_abort = 1;
  595.             retmsg = FALSE;
  596.             Fdelete(fixdst);        
  597.             goto y0;
  598.         }
  599.         copysiz -= bufsiz;
  600.     }
  601.  
  602.     Fdatime( &time, outhand, 1 );    
  603.  
  604. y0:
  605.     Fclose(outhand);
  606. y1:
  607.     Mfree(buffer);
  608. y2:
  609.     updatnum(NUMFILE, --numfiles);
  610.     Fsetdta(saved);
  611. y3:
  612.     Fclose(inhand);
  613.     Mfree(mydta);
  614.     return(retmsg);
  615. }
  616.  
  617.  
  618. /* Copy s and d into fixsrc and fixdst. Also check it is one file
  619.    copy or files and directories copy */
  620.  
  621.     int
  622. getinfo(s, d)
  623. char *s, *d;
  624. {
  625.     int     ret, sdir, ddir;
  626.  
  627.     srclen = strlen(s) + 5;     /* 1 byte for null and 4 byte for \*.* */
  628.     dstlen = strlen(d) + 17;     /* 1 for null, 4 for \*.* and 13 for folder */
  629.     srcbuf = 500;                /* initialize the buffer */
  630.     dstbuf = 500;
  631.  
  632.     while (srclen > srcbuf)
  633.       srcbuf *= 2;
  634.  
  635.     while (dstlen > dstbuf)
  636.       dstbuf *= 2;
  637.  
  638.     fixsrc = (char *)Malloc((long)srcbuf);
  639.     fixdst = (char *)Malloc((long)dstbuf);
  640.     sdir = mystrcp(s, fixsrc);
  641.  
  642.     if ( opcode == OP_DELETE )    /* do directories or files rm */
  643.       return( (sdir)? DTOD:OK );
  644.     else            /* do directories or files cp or mv */
  645.     {        
  646.        getlastpath(filestr,fixsrc);
  647.        if (((ddir = mystrcp(d, fixdst))) && (sdir))    
  648.        {                     /* dir to dir */
  649.          if (*filestr)    
  650.          {                    /* folder cp */
  651.            chkbuf(dstlen, dstbuf, &fixdst);        /* check buf size */
  652.            addfile(fixdst, filestr);    /* add the folder to dst */
  653.            ret = created(filestr);        /* create the 1st folder */
  654.            if ((!ret) || (ret == SKIP))     
  655.            {
  656.              Mfree( fixsrc );
  657.              Mfree( fixdst );
  658.              return(ret);
  659.            }
  660.            strcat(bckslsh, fixdst);
  661.          }
  662.          return (DTOD);
  663.        }
  664.        if (ddir)
  665.        {                                        /* one file to dir */
  666.          chkbuf(dstlen, dstbuf, &fixdst);        /* check buf size */
  667.          strcat(filestr, fixdst);
  668.        }
  669.        return OK;            
  670.     } 
  671. }
  672.  
  673.  
  674. created(dir)
  675. char *dir;
  676. {
  677.     int ret;
  678.  
  679.     updatbox(dir);
  680. rechkd2:                 /* update check the dir existing or not */
  681.     switch( chkdf( dir, CPDIR ) )    
  682.     {
  683.       case    QUIT:
  684.           f_abort = 1;
  685.           return(FALSE);
  686.       case    SKIP:
  687.           return(SKIP);
  688.       case    FALSE:
  689.         return(FALSE);
  690.       case     CHECK:
  691.          goto     rechkd2;
  692.       case    OK:    
  693. repeat:
  694.           if (Dcreate(fixdst))    
  695.           {
  696.             if ( write_save )
  697.               goto ll_1;
  698.  
  699.           if ((ret = do_alert(1,CNTCRTDR)) == 2)        /* retry */
  700.             goto repeat;
  701.           else if (ret == 3)        /* abort */
  702.             {             
  703.               f_abort = 1;
  704.               return(FALSE);
  705.             }
  706.         }
  707.         break;    /* default */
  708.     }
  709. ll_1:            /* update the number of dir */
  710.     updatnum(NUMDIR, --numdirs);
  711.     return(TRUE);
  712. }
  713.  
  714.  
  715. deleted()
  716. {
  717.     int    ret;
  718.     char buf[14];
  719.     
  720.     rmstarb(fixsrc);        /* remove the back slash */
  721.  
  722.     if ( !fixsrc[2] )
  723.       return( TRUE );
  724.     
  725.     getlastpath(buf, fixsrc);
  726.     updatname(CPDIR, buf);
  727. domore:
  728.     if ( Ddelete(fixsrc) )    
  729.     {
  730.       if ( ( ret = do_alert(1,CNTDELD)) == 2 )    /* retry */    
  731.         goto domore;
  732.       else if ( ret == 3 )        /* abort */
  733.         {    
  734.           f_abort = 1;
  735.           return(FALSE);
  736.         }
  737.     }
  738.  
  739.     if (opcode == OP_DELETE)    updatnum(NUMDIR, --numdirs);
  740.     return(TRUE);
  741. }
  742.  
  743.  
  744. /*  this call will copy the string inside the s to 
  745.  *     the fixs. For example,
  746.  *     if s0 -> c:\d1\d2\*.* or c:\d1\d2\f, after the call,
  747.  *    s1 -> c:\d1\d2\  or c:\d1\d2\f ;                         */
  748.  
  749. mystrcp(s0, s1 )
  750. char *s0, *s1;
  751. {
  752.     register char *ptr;
  753.  
  754.     ptr = s0;
  755.     while ((*ptr) && (*ptr != '*'))        
  756.       *s1++ = *ptr++;
  757.  
  758.     *s1 = '\0';
  759.     return((*ptr == '*') ? 1 : 0);
  760.  
  761. }
  762.  
  763.  
  764. /* check the size of source buffer */
  765.  
  766. chkbuf(len, bufsiz, src)
  767. int len, bufsiz;
  768. char **src;
  769. {
  770.  
  771.     char *ptr;
  772.  
  773.     if ((len + FILE_LEN) > bufsiz)        
  774.     {
  775.       bufsiz *= 2;
  776.       ptr = *src;
  777.       *src = (char *)Malloc((long)bufsiz);
  778.       strcpy(ptr, *src);
  779.       Mfree(ptr);
  780.     }
  781.     len += FILE_LEN;
  782. }
  783.  
  784.  
  785. /* s -> c:\d1\d2\*.* or c:\d1\d2\, obj -> f; after the call
  786.  * s -> c:\d1\d2\f                            */
  787.  
  788. addfile(s, obj)
  789. char *s, *obj;
  790. {
  791.     register char *ptr;
  792.  
  793.     ptr = s;
  794.  
  795.     while (*ptr++);    
  796.  
  797.     if (*(ptr-2) == '*')    
  798.       *(ptr-4) = '\0';
  799.       
  800.     strcat(obj, s);
  801. }
  802.  
  803.  
  804. /* src -> c:\d1\d2\*.* or -> c:\d3\d5\, after the call,
  805.  * src -> c:\d1\d2 or -> c:\d3\d5                */
  806.  
  807. rmstarb(src)
  808. char *src;
  809. {
  810.     register char *ptr;
  811.  
  812.     ptr = src;
  813.     while (*ptr++);        
  814.  
  815.     if (*(ptr-2) == '\\')        /* src -> c:\d3\d5\ */    
  816.       *(ptr-2) = '\0';
  817.     else                 /* src -> c:\d3\d5\*.*  */
  818.       *(ptr-5) = '\0';
  819. }
  820.  
  821.  
  822. /* str -> c:\d1\d2\ or c:\d1\d2\*.* or c:\d2\d4 or c:\; after the call,
  823.  * str -> c:\d1\  or c:\d2\ or c:\        */
  824.  
  825. backdir(str)
  826. char *str;
  827. {
  828.     register char *ptr;
  829.  
  830.     ptr = str;
  831.     while (*ptr++);
  832.  
  833.     ptr -= 2;
  834.       if (*(ptr-1) == ':')    /* str -> c:\ */
  835.       return OK;
  836.     if (*ptr == '*')        /* c:\d1\d2\*.* */
  837.       ptr -= 3;
  838.     while (*--ptr != '\\'); /* str -> c:\d1\d2 or c:\d1\d2\ */
  839.  
  840.     *(ptr + 1) = '\0';
  841. }
  842.  
  843.  
  844. /* check the directory or file is exist or not */
  845.  
  846.     int
  847. chkdf( str, flag )
  848.     char *str;
  849.     int flag;
  850. {
  851.     int     ret;
  852.  
  853.     if ( write_save )
  854.       return( OK );
  855.  
  856.     if ( flag == CPFILE )
  857.     {
  858.       if ((ret = Fopen(fixdst, 0)) >= 0)    
  859.       {                     /* file exist */
  860.         Fclose( ret );
  861.         return(edname(str, CPFILE));
  862.       }
  863.     }
  864.     else
  865.     {
  866.       Dsetdrv(*fixdst - 'A');
  867.       if (!(ret = Dsetpath(fixdst+2)))    /* direcory exist */
  868.         return(edname(str, CPDIR));     /* update name conflict box */
  869.     }
  870.  
  871.     /* 0xFFDE: path not found. 0xFFDF: file not found. */
  872.     return (((ret == 0xFFDF)||(ret == 0xFFDE))? OK:FALSE);    
  873. }
  874.  
  875.  
  876. edname(src, kind)
  877.     char     *src;
  878.     int    kind;
  879. {
  880.     int     but;
  881.     REG OBJECT    *obj;
  882.  
  883.     obj = get_tree( SAMENAME );
  884.  
  885.     pack(src, 0);
  886.     strcpy(src, ((TEDINFO *)(obj[FNAME].ob_spec))->te_ptext);
  887.     strcpy(src, ((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext);
  888.     obj[COPY].ob_state = NORMAL;
  889.     obj[SKIP].ob_state = NORMAL;
  890.     obj[QUIT].ob_state = NORMAL;
  891.     desk_wait( FALSE );
  892.     fm_draw( SAMENAME );
  893.  
  894.     switch((but = form_do(obj, 0)))    
  895.     {
  896.         case COPY:    
  897.                if (!strcmp(((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext, src)) 
  898.           {            /* user edit the new name */
  899.         strcpy( ((TEDINFO *)(obj[EDFNAME].ob_spec))->te_ptext,src);
  900.         strcpy( src, ((TEDINFO *)(cpbox[kind].ob_spec))->te_ptext);
  901.         pack(src,1);
  902.         backdir(fixdst);
  903.         strcat(src, fixdst);
  904.         but = CHECK;
  905.           }    else {/* check if the source and destination are the same */
  906.               if (kind == CPDIR)
  907.                   rmstarb(fixsrc);
  908.             if (strcmp(fixsrc, fixdst))/* they are the same */
  909.                 but = SKIP;
  910.               if (kind == CPDIR)
  911.                 strcat(bckslsh, fixsrc);
  912.           }
  913.           break;
  914.           
  915.         case SKIP:
  916.         case QUIT:    
  917.           break;
  918.       }
  919.  
  920.           desk_wait( TRUE );
  921.       
  922.       if ( d_display )
  923.         fm_draw( CPBOX );
  924.       else
  925.         namecon = TRUE;
  926.  
  927.       if (but != CHECK)        
  928.         pack(src, 1);
  929.  
  930.       return but;
  931. }
  932.  
  933. /* pack     : src -> file    rsc, after the call; src -> file.rsc    */
  934. /* unpack: buf -> unpack.rsc, after the call, buf -> unpack  rsc.  */
  935.  
  936. pack( src, flag )
  937.     char *src;
  938.     int flag;
  939. {
  940.     char temp[14];
  941.  
  942.     if (flag)     unfmt_str( src, temp );    /* pack */
  943.     else        fmt_str( src, temp );    /* unpack */
  944.     strcpy( temp, src );
  945. }
  946.  
  947. /* src -> c:\f or c:\d1\f or c:\f\, or c:\f\*.*, after the call,
  948.    buf -> f. But if src ->c:\, then buf -> Null     */
  949.  
  950. getlastpath(buf, src)
  951.     register char *buf, *src;
  952. {
  953.     register    char *tmp;
  954.  
  955.     tmp = src;
  956.      *buf = '\0';
  957.  
  958.     while (*tmp++);    
  959.  
  960.     tmp -= 2;                        
  961.     if (*tmp == '*')            /* src -> c:\f\*.* */
  962.         tmp -= 3;                
  963.     if (*(tmp-1) == ':')            /* src -> c:\ */
  964.       return OK;
  965.  
  966.       while (*--tmp != '\\');            /* back one more path */    
  967.  
  968.     while ((*buf = *++tmp) != '\\')
  969.         if (!*buf++)    return OK;
  970.     *buf = '\0';
  971. }
  972.  
  973.  
  974. /* up date the number of file or directory in the dialog box */
  975.  
  976. updatnum(obj, num)
  977. int obj;
  978. long num;
  979. {
  980.     if ( d_display )
  981.     {
  982.       f_str( cpbox, obj, num );
  983.       draw_fld( cpbox, obj );
  984.     }
  985. }
  986.  
  987. /* up date the file or directory in the dialog box */
  988.  
  989. updatname(obj, str)
  990. int obj; 
  991. char *str;
  992. {
  993.     if ( d_display )
  994.     {
  995.       pack(str,0);
  996.       strcpy(str, ((TEDINFO *)(cpbox[obj].ob_spec))->te_ptext);
  997.       pack(str,1);
  998.       draw_fld( cpbox, obj );
  999.     }
  1000. }
  1001.  
  1002.  
  1003. updatbox(str)
  1004. char *str;
  1005. {
  1006.     if ( d_display )
  1007.     {
  1008.       pack(str,0);
  1009.       strcpy(str, ((TEDINFO *)(cpbox[CPDIR].ob_spec))->te_ptext);
  1010.       pack(str,1);
  1011.       strcpy("_", ((TEDINFO *)(cpbox[CPFILE].ob_spec))->te_ptext);
  1012.       objc_draw( cpbox, HIDECBOX, MAX_DEPTH, 0, 0, full.w, full.h );
  1013.     }
  1014. }
  1015.  
  1016.  
  1017. updesk( s )
  1018.     BYTE    *s;
  1019. {
  1020.     REG WORD    i;
  1021.     WORD    limit,found;
  1022.     REG OBJECT    *obj;
  1023.  
  1024.     obj = background;
  1025.  
  1026.     limit = obj->ob_tail;
  1027.     found = FALSE;
  1028.  
  1029.     for ( i = 1; i <= limit; i++ )
  1030.       if ( ( obj[i].ob_flags != HIDETREE ) && ( backid[i].i_type == XFILE ) )
  1031.         if ( strcmp( s, backid[i].i_path ) )
  1032.         {
  1033.           obj[i].ob_state = SELECTED;
  1034.           found = TRUE;
  1035.         }
  1036.     if ( found )
  1037.     {
  1038.       lp_collect();
  1039.       back_update = TRUE;
  1040.     }
  1041. }
  1042.